package com.zdkj.subway.support.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdkj.common.core.util.R;
import com.zdkj.common.log.annotation.SysLog;
import com.zdkj.common.security.util.ObjectUtils;
import com.zdkj.subway.support.dto.in.SwParamTicketPriceConfigDTO;
import com.zdkj.subway.support.entity.SwParamTicketPriceConfig;
import com.zdkj.subway.support.service.SwParamTicketPriceConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 * 票价收费配置
 *
 * @author cui_com
 * @date 2020-01-15 18:38:44
 */
@RestController
@AllArgsConstructor
@RequestMapping("/swparamticketpriceconfig")
@Api(value = "swparamticketpriceconfig", tags = "票价收费配置管理")
public class SwParamTicketPriceConfigController {

    private final SwParamTicketPriceConfigService swParamTicketPriceConfigService;

    /**
     * 分页查询
     *
     * @param page                     分页对象
     * @param swParamTicketPriceConfig 票价收费配置
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    public R getSwParamTicketPriceConfigPage(Page page, SwParamTicketPriceConfig swParamTicketPriceConfig) {
        return R.ok(swParamTicketPriceConfigService.page(page, Wrappers.query(swParamTicketPriceConfig)));
    }


    /**
     * 通过id查询票价收费配置
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}")
    public R getById(@PathVariable("id") Integer id) {
        return R.ok(swParamTicketPriceConfigService.getById(id));
    }

    /**
     * 新增票价收费配置
     *
     * @param swParamTicketPriceConfig 票价收费配置
     * @return R
     */
    @ApiOperation(value = "新增票价收费配置", notes = "新增票价收费配置")
    @SysLog("新增票价收费配置")
    @PostMapping
    @PreAuthorize("@pms.hasPermission('support_sw_param_ticket_price_config_add')")
    public R save(@RequestBody SwParamTicketPriceConfig swParamTicketPriceConfig) {
        SwParamTicketPriceConfig defaultObj =
                ObjectUtils.getDefaultObj(SwParamTicketPriceConfig.class);
        BeanUtils.copyProperties(swParamTicketPriceConfig, defaultObj);
        return R.ok(swParamTicketPriceConfigService.save(defaultObj));
    }

    /**
     * 修改票价收费配置
     *
     * @param swParamTicketPriceConfig 票价收费配置
     * @return R
     */
    @ApiOperation(value = "修改票价收费配置", notes = "修改票价收费配置")
    @SysLog("修改票价收费配置")
    @PutMapping
    @PreAuthorize("@pms.hasPermission('support_sw_param_ticket_price_config_edit')")
    public R updateById(@RequestBody SwParamTicketPriceConfigDTO swParamTicketPriceConfig) {
        SwParamTicketPriceConfig obj = new SwParamTicketPriceConfig();
        BeanUtils.copyProperties(swParamTicketPriceConfig, obj);
        return R.ok(swParamTicketPriceConfigService.updateById(obj));
    }

    /**
     * 通过id删除票价收费配置
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除票价收费配置", notes = "通过id删除票价收费配置")
    @SysLog("通过id删除票价收费配置")
    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('support_sw_param_ticket_price_config_del')")
    public R removeById(@PathVariable Integer id) {
        return R.ok(swParamTicketPriceConfigService.removeById(id));
    }

}
